package com.ruoyi.web.controller.api.patient;

import com.ruoyi.common.constant.HttpStatusCusCode;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.api.patient.GroupDto;
import com.ruoyi.system.domain.api.patient.RelationshipDto;
import com.ruoyi.system.service.api.patient.IRelationshipApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;


/**
 * 医生相关Controller
 *
 * @author sergio
 * @date 2024-11-14
 */
@Api("医生信息")
@RestController
@RequestMapping("/api/patient/doctor")
public class DoctorApiController extends BaseController {

    @Autowired
    private IRelationshipApiService relationshipApiService;

    /**
     * 患者关注|取关医生|拉黑医生
     *
     * @author sergio
     * @date 2024/11/14
     */
    @ApiOperation("患者关注|取关医生|拉黑医生")
    @PostMapping("/follow")
    public AjaxResult follow(@RequestBody @Valid RelationshipDto relationshipDto)
    {
        if (relationshipDto.getDoctorInfo() != null &&
                relationshipDto.getPatientInfo() != null &&
                relationshipDto.getDoctorInfo().getDoctorId() != null &&
                relationshipDto.getPatientInfo().getPatientId() != null) {
            // 前端必须传绑定关系Relation为 Followed / unFollowed
            if(relationshipDto.getRelation() == null) {
                return AjaxResult.error(HttpStatusCusCode.RELATION_NOT_FOUND.getCode(),HttpStatusCusCode.RELATION_NOT_FOUND.getMessage());
            }
            // 两者都不为空时的处理逻辑
            Integer status = relationshipApiService.addRelationship(relationshipDto);
            if (status == 9001) {
                return AjaxResult.error(HttpStatusCusCode.DOCTOR_INFO_NOT_FOUND.getCode(),HttpStatusCusCode.DOCTOR_INFO_NOT_FOUND.getMessage());
            } else {
                return AjaxResult.success();
            }
        } else {
            // 任意一个为空时的处理逻辑
            return AjaxResult.error(HttpStatusCusCode.PARAMS_NOT_NULL.getCode(),HttpStatusCusCode.PARAMS_NOT_NULL.getMessage());
        }

    }
    /**
     * 绑定医生患者关系为问诊关系
     *
     * @author sergio
     * @date 2024/11/14
     */
    @ApiOperation("绑定医生患者关系为问诊关系")
    @PostMapping("/con")
    public AjaxResult consultation(@RequestBody @Valid RelationshipDto relationshipDto)
    {
        if (relationshipDto.getDoctorInfo() != null &&
                relationshipDto.getPatientInfo() != null &&
                relationshipDto.getDoctorInfo().getDoctorId() != null &&
                relationshipDto.getPatientInfo().getPatientId() != null) {
            // 两者都不为空时的处理逻辑
            // 前端必须传绑定关系Consultation为 con / uncon
            if(relationshipDto.getConsultation() == null) {
                return AjaxResult.error(HttpStatusCusCode.RELATION_NOT_FOUND.getCode(),HttpStatusCusCode.RELATION_NOT_FOUND.getMessage());
            }
            Integer status = relationshipApiService.addConsultation(relationshipDto);
            if (status == 9001) {
                return AjaxResult.error(HttpStatusCusCode.DOCTOR_INFO_NOT_FOUND.getCode(),HttpStatusCusCode.DOCTOR_INFO_NOT_FOUND.getMessage());
            } else {
                return AjaxResult.success();
            }
        } else {
            // 任意一个为空时的处理逻辑
            return AjaxResult.error(HttpStatusCusCode.PARAMS_NOT_NULL.getCode(),HttpStatusCusCode.PARAMS_NOT_NULL.getMessage());
        }

    }


}

